

import json
import random
import threading
from lib.queue import RabbitMQ
from concurrent.futures import ThreadPoolExecutor

queue = RabbitMQ()

_random = random.Random()
news_list = [268443, 268508, 268492, 268548, 268523, 268521]
actions = [2, 3, 4, 5, 6, 7, 8, 9]


def send(i):
    queue.send(
        name='foreign-news-event',
        data=json.dumps({'user_id': i, 'article_id': _random.choice(news_list), 'action_id': _random.choice(actions)}, ensure_ascii=False),
        properties={'content_type': queue.ContentType.JSON}
    )


with ThreadPoolExecutor(20) as pool:
    pool.map(send, range(100))

